home *** CD-ROM | disk | FTP | other *** search
/ The Arsenal Files 8 / The Arsenal Files Collection #8 (Arsenal Computer) (1996).ISO / prg_casm / snpd9611.zip / SNIPTREE.C < prev    next >
C/C++ Source or Header  |  1996-11-24  |  3KB  |  107 lines

  1. /* +++Date last modified: 27-Oct-1996 */
  2.  
  3. /* SNIPTREE
  4.  
  5.    Written by Tom Torfs (2:292/516@fidonet.org)
  6.    I hereby donate this code to the public domain
  7.  
  8.    Builds custom directory structure for SNIPPETS by reading SNIPPETS.NDX
  9.  
  10.    Requires POSIX-function mkdir(), rest should be ANSI C.
  11. */
  12.  
  13. #include <stdio.h>
  14. #include <stdlib.h>
  15. #include <string.h>
  16.  
  17. #include "unistd.h"
  18.  
  19. int main(void)
  20. {
  21.       FILE *fp;
  22.       char buf[100];
  23.       char curpath[80];
  24.       char oldfile[80],newfile[80];
  25.       int i;
  26.       int skiparea;
  27.  
  28.       puts("SNIPTREE by Tom Torfs");
  29.  
  30.       if ((fp=fopen("SNIPPETS.NDX","r"))==NULL)
  31.       {
  32.             puts("ERROR: can't open SNIPPETS.NDX for reading");
  33.             return 1;
  34.       }
  35.  
  36.       while (1)
  37.       {
  38.             do
  39.             {
  40.                   fgets(buf,100,fp);
  41.                   if (feof(fp)) goto finished;
  42.             }
  43.             while (memcmp(buf,"|=========",10))
  44.                   ;
  45.             fgets(buf,100,fp);
  46.             if (feof(fp)) goto finished;
  47.             if (!memcmp(buf,"|=========",10))
  48.             {
  49.                   fgets(buf,100,fp); /* empty */
  50.                   fgets(buf,100,fp); /* section name */
  51.                   fgets(buf,100,fp); /* empty */
  52.                   fgets(buf,100,fp); /* |======================= */
  53.                   fgets(buf,100,fp); /* |======================= */
  54.                   continue;
  55.             }
  56.             strtok(buf,"\n");
  57.             printf("\nFile area: %s\n",buf+2);
  58.             if (!memicmp(buf+2,"Files deleted",13))
  59.             {
  60.                   skiparea = 1;
  61.                   puts("--> SKIPPING");
  62.             }
  63.             else
  64.             {
  65.                   skiparea = 0;
  66.                   printf("Subdirectory (empty=don't move): ");
  67.                   fgets(curpath,80,stdin);
  68.                   i = strlen(curpath);
  69.                   while (i>0 && (curpath[i-1]=='\n' || curpath[i-1]=='\\'
  70.                                  || curpath[i-1]=='/'))
  71.                         i--;
  72.                   curpath[i] = '\0';
  73.                   if (i>0)
  74.                         mkdir(curpath);
  75.             }
  76.             fgets(buf,100,fp); /* |======================= */
  77.             fgets(buf,100,fp); /* | File  O/S  Description */
  78.             fgets(buf,100,fp); /* | ----  ---  ----------- */
  79.             while (1)
  80.             {
  81.                   fgets(buf,100,fp);
  82.                   if (feof(fp)) goto finished;
  83.                   if (buf[0]=='\n')
  84.                         break;
  85.                   if (skiparea)
  86.                         continue;
  87.                   strtok(buf+2," ");
  88.                   strcpy(oldfile,buf+2);
  89.                   if (curpath[0]=='\0' || !stricmp(oldfile,"SNIPPETS.NDX"))
  90.                         printf("%s (not moved)\n",oldfile);
  91.                   else
  92.                   {
  93.                         sprintf(newfile,"%s\\%s",curpath,oldfile);
  94.                         printf("%s -> %s\n",oldfile,newfile);
  95.                         rename(oldfile,newfile);
  96.                   }
  97.             }
  98.       }
  99. finished:
  100.  
  101.       puts("\nFinished.");
  102.  
  103.       fclose(fp);
  104.  
  105.       return 0;
  106. }
  107.